package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.listener.IClickCancleListener;
import com.keyancompany.zhongbaopingtai.model.FindModel;
import com.keyancompany.zhongbaopingtai.model.TeamRewardModel;
import com.keyancompany.zhongbaopingtai.weight.CircleImageView;

/**
 * Created by firefox on 2016/6/14.
 */
public class PercentAdapter extends ListAdapter<TeamRewardModel> {

    private IClickCancleListener listener;
    java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");

    public PercentAdapter(Context ctx, IClickCancleListener listener) {
        super(ctx);
        this.listener = listener;
    }

    @Override
    public int getContentViewId() {
        return R.layout.item_percent;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {

        return new FindHolder(contentView);
    }

    @Override
    public void setItemView(final int position, HolderView contentView, TeamRewardModel item) {

        FindHolder hold = (FindHolder) contentView;
        hold.name.setText(item.getUsername());
        if (TextUtils.isEmpty(item.getPercentage())) {
            hold.percent.setText("0.00%");
        } else
            hold.percent.setText(df.format(Double.valueOf(item.getPercentage()) * 100) + "%");
    }


    class FindHolder extends HolderView {

        CircleImageView icon;

        TextView name;

        TextView zhiwu;

        TextView percent;


        public FindHolder(View contentView) {
            icon = (CircleImageView) contentView.findViewById(R.id.icon);
            name = (TextView) contentView.findViewById(R.id.name);
            zhiwu = (TextView) contentView.findViewById(R.id.zhifu);
            percent = (TextView) contentView.findViewById(R.id.percent);
        }
    }
}
